var searchData = {
    "thisSearch": "https://www.baidu.com/s?wd=",
    "thisSearchIcon": "./images/sou/sou1.png",
    "data": [{
        name: "百度",
        url: "https://www.baidu.com/s?wd=",
        img: "./images/sou/sou1.png"
    }, {
        name: "Google",
        url: "https://www.google.com/search?q=",
        img: "./images/sou/sou2.png"
    }, {
        name: "Bing搜索",
        url: "https://cn.bing.com/search?q=",
        img: "./images/sou/sou3.png"
    }, {
        name: "360搜索",
        url: "https://www.so.com/s?q=",
        img: "./images/sou/sou4.png"
    }, {
        name: "搜狗搜索",
        url: "https://www.sogou.com/web?query=",
        img: "./images/sou/sou5.png"
    }, {
        name: "多吉搜索",
        url: "https://www.dogedoge.com/results?q=",
        img: "./images/sou/sou6.png"
    }]
};
var localSearchData = localStorage.getItem("searchData");
if (localSearchData) {
    searchData = JSON.parse(localSearchData)
}
;$("#txt").keydown(function(e) {
    if (e.keyCode === 13) {
        window.open(searchData.thisSearch + $("#txt").val());
    }
});
for (var i = 0; i < searchData.data.length; i++) {
    $(".search-engine-list").append('<li><img src="' + searchData.data[i].img + '">' + searchData.data[i].name + '</li>')
}
;$(".search-icon, .search-engine").hover(function() {
    $(".search-engine").css("display", "block")
}, function() {
    $(".search-engine").css("display", "none")
});
$(".search-engine-list li").click(function() {
    var index = $(this).index();
    searchData.thisSearchIcon = searchData.data[index].img;
    $(".search-icon").attr('src', searchData.thisSearchIcon);
    searchData.thisSearch = searchData.data[index].url;
    $(".search-engine").css("display", "none");
    console.log(searchData.data[index].img, searchData.data[index].url);
    localStorage.searchData = JSON.stringify(searchData)
});
$(".search-icon").attr('src', searchData.thisSearchIcon);
;$("#search-btn").click(function() {
    var textValue = $("#txt").val();
    if (textValue) {
        window.open(searchData.thisSearch + $("#txt").val());
    }
});
